package com.btl.component.crypto.aes;

import com.btl.boot.core.util.JsonUtils;
import com.btl.component.crypto.aes.dto.AesCryptoDto;
import com.btl.component.crypto.aes.util.AESCryptoUtil;
import com.btl.component.crypto.aes.util.RSACryptoUtil;

import java.util.Map;

public class SecurityTest {
    public static void main(String[] args) throws Exception {
        String key = "gCCMFxVYm8EeqknKE4ExHs2WMwkr5GoWPG9ixR4v30o=";
        String payloads = JsonUtils.toJsonString(Map.of("channelId", 1, "socialId", 1234567890, "chatId", 1));
        assert payloads != null;
        String encrypt = AESCryptoUtil.encrypt(payloads, key);
        AesCryptoDto secReq = new AesCryptoDto();
        secReq.setPayload(encrypt);
        String sign = RSACryptoUtil.sign(encrypt);
        secReq.setSignature(sign);
        System.out.println(JsonUtils.toJsonString(secReq));
        // 校验签名
        boolean verify = RSACryptoUtil.verify(encrypt, sign);
        System.out.println(verify);
        String decrypt = AESCryptoUtil.decrypt(secReq.getPayload(), key);
        System.out.println(decrypt);
        String decrypt1 = AESCryptoUtil.decrypt("RguDKbUq+wDYRjaDLXLjbYmNBQtGs0+E1wFsJ7+4gso=", key);
        System.out.println(decrypt1);
    }
}
